home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-13.z / elisp-13
Encoding:
GNU Info File  |  1994-08-02  |  47.4 KB  |  1,197 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Yes-or-No Queries,  Next: Multiple Queries,  Prev: Completion,  Up: Minibuffers
  41.  
  42. Yes-or-No Queries
  43. =================
  44.  
  45.    This section describes functions used to ask the user a yes-or-no
  46. question.  The function `y-or-n-p' can be answered with a single
  47. character; it is useful for questions where an inadvertent wrong answer
  48. will not have serious consequences.  `yes-or-no-p' is suitable for more
  49. momentous questions, since it requires three or four characters to
  50. answer.
  51.  
  52.    Strictly speaking, `yes-or-no-p' uses the minibuffer and `y-or-n-p'
  53. does not; but it seems best to describe them together.
  54.  
  55.  - Function: y-or-n-p PROMPT
  56.      This function asks the user a question, expecting input in the echo
  57.      area.  It returns `t' if the user types `y', `nil' if the user
  58.      types `n'.  This function also accepts SPC to mean yes and DEL to
  59.      mean no.  It accepts `C-]' to mean "quit", like `C-g', because the
  60.      question might look like a minibuffer and for that reason the user
  61.      might try to use `C-]' to get out.  The answer is a single
  62.      character, with no RET needed to terminate it.  Upper and lower
  63.      case are equivalent.
  64.  
  65.      "Asking the question" means printing PROMPT in the echo area,
  66.      followed by the string `(y or n) '.  If the input is not one of
  67.      the expected answers (`y', `n', `SPC', `DEL', or something that
  68.      quits), the function responds `Please answer y or n.', and repeats
  69.      the request.
  70.  
  71.      This function does not actually use the minibuffer, since it does
  72.      not allow editing of the answer.  It actually uses the echo area
  73.      (*note The Echo Area::.), which uses the same screen space as the
  74.      minibuffer.  The cursor moves to the echo area while the question
  75.      is being asked.
  76.  
  77.      The meanings of answers, even `y' and `n', are not hardwired.
  78.      They are controlled by the keymap `query-replace-map'.  *Note
  79.      Replacement::.
  80.  
  81.      In the following example, the user first types `q', which is
  82.      invalid.  At the next prompt the user types `n'.
  83.  
  84.           (y-or-n-p "Do you need a lift? ")
  85.           
  86.           ;; After evaluating the preceding expression,
  87.           ;;   the following prompt appears in the echo area:
  88.  
  89.           ---------- Echo area ----------
  90.           Do you need a lift? (y or n)
  91.           ---------- Echo area ----------
  92.           
  93.           ;; If the user then types `q', the following appears:
  94.           ---------- Echo area ----------
  95.           Please answer y or n.  Do you need a lift? (y or n)
  96.           ---------- Echo area ----------
  97.           
  98.           ;; When the user types a valid answer,
  99.           ;;   it is displayed after the question:
  100.           ---------- Echo area ----------
  101.           Do you need a lift? (y or n) y
  102.           ---------- Echo area ----------
  103.  
  104.      Note that we show successive lines of echo area messages here.
  105.      Only one actually appears on the screen at a time.
  106.  
  107.  - Function: yes-or-no-p PROMPT
  108.      This function asks the user a question, expecting input in
  109.      minibuffer.  It returns `t' if the user enters `yes', `nil' if the
  110.      user types `no'.  The user must type RET to finalize the response.
  111.      Upper and lower case are equivalent.
  112.  
  113.      `yes-or-no-p' starts by displaying PROMPT in the echo area,
  114.      followed by `(yes or no) '.  The user must type one of the
  115.      expected responses; otherwise, the function responds `Please answer
  116.      yes or no.', waits about two seconds and repeats the request.
  117.  
  118.      `yes-or-no-p' requires more work from the user than `y-or-n-p' and
  119.      is appropriate for more crucial decisions.
  120.  
  121.      Here is an example:
  122.  
  123.           (yes-or-no-p "Do you really want to remove everything? ")
  124.           
  125.           ;; After evaluating the preceding expression,
  126.           ;;   the following prompt appears,
  127.           ;;   with an empty minibuffer:
  128.  
  129.           ---------- Buffer: minibuffer ----------
  130.           Do you really want to remove everything? (yes or no)
  131.           ---------- Buffer: minibuffer ----------
  132.  
  133.      If the user first types `y RET', which is invalid because this
  134.      function demands the entire word `yes', it responds by displaying
  135.      these prompts, with a brief pause between them:
  136.  
  137.           ---------- Buffer: minibuffer ----------
  138.           Please answer yes or no.
  139.           Do you really want to remove everything? (yes or no)
  140.           ---------- Buffer: minibuffer ----------
  141.  
  142. 
  143. File: elisp,  Node: Multiple Queries,  Next: Minibuffer Misc,  Prev: Yes-or-No Queries,  Up: Minibuffers
  144.  
  145. Asking Multiple Y-or-N Queries
  146. ==============================
  147.  
  148.  - Function: map-y-or-n-p PROMPTER ACTOR LIST &optional HELP
  149.           ACTION-ALIST
  150.      This function, new in Emacs 19, asks the user a series of
  151.      questions, reading a single-character answer in the echo area for
  152.      each one.
  153.  
  154.      The value of LIST specifies what varies from question to question
  155.      within the series.  It should be either a list of objects or a
  156.      generator function.  If it is a function, it should expect no
  157.      arguments, and should return either the next object or `nil'
  158.      meaning there are no more questions.
  159.  
  160.      The argument PROMPTER specifies how to ask each question.  If
  161.      PROMPTER is a string, the question text is computed like this:
  162.  
  163.           (format PROMPTER OBJECT)
  164.  
  165.      where OBJECT is the next object to ask about (as obtained from
  166.      LIST).
  167.  
  168.      If not a string, PROMPTER should be a function of one argument
  169.      (the next object to ask about) and should return the question text.
  170.  
  171.      The argument ACTOR says how to act on the answers that the user
  172.      gives.  It should be a function of one argument, and it is called
  173.      with each object that the user says yes for.  Its argument is
  174.      always an object obtained from LIST.
  175.  
  176.      If the argument HELP is given, it should be a list of this form:
  177.  
  178.           (SINGULAR PLURAL ACTION)
  179.  
  180.      where SINGULAR is a string containing a singular noun that
  181.      describes the objects conceptually being acted on, PLURAL is the
  182.      corresponding plural noun, and ACTION is a transitive verb
  183.      describing what ACTOR does.
  184.  
  185.      If you don't specify HELP, the default is `("object" "objects"
  186.      "act on")'.
  187.  
  188.      Each time a question is asked, the user may enter `y', `Y', or SPC
  189.      to act on that object; `n', `N', or DEL to skip that object; `!'
  190.      to act on all following objects; ESC or `q' to exit (skip all
  191.      following objects); `.' (period) to act on the current object and
  192.      then exit; or `C-h' to get help.  These are the same answers that
  193.      `query-replace' accepts.  The keymap `query-replace-map' defines
  194.      their meaning for `map-y-or-n-p' as well as for `query-replace';
  195.      see *Note Replacement::.
  196.  
  197.      You can use ACTION-ALIST to specify additional possible answers
  198.      and what they mean.  It is an alist of elements of the form `(CHAR
  199.      FUNCTION HELP)', each of which defines one additional answer.  In
  200.      this element, CHAR is a character (the answer); FUNCTION is a
  201.      function of one argument (an object from LIST); HELP is a string.
  202.  
  203.      When the user responds with CHAR, `map-y-or-n-p' calls FUNCTION.
  204.      If it returns non-`nil', the object is considered "acted upon",
  205.      and `map-y-or-n-p' advances to the next object in LIST.  If it
  206.      returns `nil', the prompt is repeated for the same object.
  207.  
  208.      The return value of `map-y-or-n-p' is the number of objects acted
  209.      on.
  210.  
  211. 
  212. File: elisp,  Node: Minibuffer Misc,  Prev: Multiple Queries,  Up: Minibuffers
  213.  
  214. Minibuffer Miscellany
  215. =====================
  216.  
  217.    This section describes some basic functions and variables related to
  218. minibuffers.
  219.  
  220.  - Command: exit-minibuffer
  221.      This command exits the active minibuffer.  It is normally bound to
  222.      keys in minibuffer local keymaps.
  223.  
  224.  - Command: self-insert-and-exit
  225.      This command exits the active minibuffer after inserting the last
  226.      character typed on the keyboard (found in `last-command-char';
  227.      *note Command Loop Info::.).
  228.  
  229.  - Command: previous-history-element N
  230.      This command replaces the minibuffer contents with the value of the
  231.      Nth previous (older) history element.
  232.  
  233.  - Command: next-history-element N
  234.      This command replaces the minibuffer contents with the value of the
  235.      Nth more recent history element.
  236.  
  237.  - Command: previous-matching-history-element PATTERN
  238.      This command replaces the minibuffer contents with the value of the
  239.      previous (older) history element that matches PATTERN.  At the
  240.      time of printing, we have not made a final decision about how to
  241.      get the pattern interactively or how to match it against history
  242.      elements.
  243.  
  244.  - Command: next-matching-history-element PATTERN
  245.      This command replaces the minibuffer contents with the value of the
  246.      next (newer) history element that matches PATTERN.
  247.  
  248.  - Variable: minibuffer-setup-hook
  249.      This is a normal hook that is run whenever the minibuffer is
  250.      entered.
  251.  
  252.  - Variable: minibuffer-help-form
  253.      The current value of this variable is used to rebind `help-form'
  254.      locally inside the minibuffer (*note Help Functions::.).
  255.  
  256.  - Function: minibuffer-window &optional FRAME
  257.      This function returns the window that is used for the minibuffer.
  258.      In Emacs 18, there is one and only one minibuffer window; this
  259.      window always exists and cannot be deleted.  In Emacs 19, each
  260.      frame can have its own minibuffer, and this function returns the
  261.      minibuffer window used for frame FRAME (which defaults to the
  262.      currently selected frame).
  263.  
  264.  - Function: window-minibuffer-p WINDOW
  265.      This function returns non-`nil' if WINDOW is a minibuffer window.
  266.  
  267.    It is not correct to determine whether a given window is a
  268. minibuffer by comparing it with the result of `(minibuffer-window)',
  269. because there can be more than one minibuffer window there is more than
  270. one frame.
  271.  
  272.  - Function: minibuffer-window-active-p WINDOW
  273.      This function returns non-`nil' if WINDOW, assumed to be a
  274.      minibuffer window, is currently active.
  275.  
  276.  - Variable: minibuffer-scroll-window
  277.      If the value of this variable is non-`nil', it should be a window
  278.      object.  When the function `scroll-other-window' is called in the
  279.      minibuffer, it scrolls this window.
  280.  
  281.    Finally, some functions and variables deal with recursive minibuffers
  282. (*note Recursive Editing::.):
  283.  
  284.  - Function: minibuffer-depth
  285.      This function returns the current depth of activations of the
  286.      minibuffer, a nonnegative integer.  If no minibuffers are active,
  287.      it returns zero.
  288.  
  289.  - User Option: enable-recursive-minibuffers
  290.      If this variable is non-`nil', you can invoke commands (such as
  291.      `find-file') which use minibuffers even while in the minibuffer
  292.      window.  Such invocation produces a recursive editing level for a
  293.      new minibuffer.  The outer-level minibuffer is invisible while you
  294.      are editing the inner one.
  295.  
  296.      This variable only affects invoking the minibuffer while the
  297.      minibuffer window is selected.   If you switch windows while in the
  298.      minibuffer, you can always invoke minibuffer commands while some
  299.      other window is selected.
  300.  
  301.    If a command name has a property `enable-recursive-minibuffers'
  302. which is non-`nil', then the command can use the minibuffer to read
  303. arguments even if it is invoked from the minibuffer.  The minibuffer
  304. command `next-matching-history-element' (normally bound to `M-s' in the
  305. minibuffer) uses this feature.
  306.  
  307. 
  308. File: elisp,  Node: Command Loop,  Next: Keymaps,  Prev: Minibuffers,  Up: Top
  309.  
  310. Command Loop
  311. ************
  312.  
  313.    When you run Emacs, it enters the "editor command loop" almost
  314. immediately.  This loop reads key sequences, executes their definitions,
  315. and displays the results.  In this chapter, we describe how these things
  316. are done, and the subroutines that allow Lisp programs to do them.
  317.  
  318. * Menu:
  319.  
  320. * Command Overview::    How the command loop reads commands.
  321. * Defining Commands::   Specifying how a function should read arguments.
  322. * Interactive Call::    Calling a command, so that it will read arguments.
  323. * Command Loop Info::   Variables set by the command loop for you to examine.
  324. * Input Events::    What input looks like when you read it.
  325. * Reading Input::       How to read input events from the keyboard or mouse.
  326. * Waiting::             Waiting for user input or elapsed time.
  327. * Quitting::            How `C-g' works.  How to catch or defer quitting.
  328. * Prefix Command Arguments::    How the commands to set prefix args work.
  329. * Recursive Editing::   Entering a recursive edit,
  330.                           and why you usually shouldn't.
  331. * Disabling Commands::  How the command loop handles disabled commands.
  332. * Command History::     How the command history is set up, and how accessed.
  333. * Keyboard Macros::     How keyboard macros are implemented.
  334.  
  335. 
  336. File: elisp,  Node: Command Overview,  Next: Defining Commands,  Up: Command Loop
  337.  
  338. Command Loop Overview
  339. =====================
  340.  
  341.    The first thing the command loop must do is read a key sequence,
  342. which is a sequence of events that translates into a command.  It does
  343. this by calling the function `read-key-sequence'.  Your Lisp code can
  344. also call this function (*note Key Sequence Input::.).  Lisp programs
  345. can also do input at a lower level with `read-event' (*note Reading One
  346. Event::.) or discard pending input with `discard-input' (*note Peeking
  347. and Discarding::.).
  348.  
  349.    The key sequence is translated into a command through the currently
  350. active keymaps.  *Note Key Lookup::, for information on how this is
  351. done.  The result should be a keyboard macro or an interactively
  352. callable function.  If the key is `M-x', then it reads the name of
  353. another command, which is used instead.  This is done by the command
  354. `execute-extended-command' (*note Interactive Call::.).
  355.  
  356.    Once the command is chosen, it must be executed, which includes
  357. reading arguments to be given to it.  This is done by calling
  358. `command-execute' (*note Interactive Call::.).  For commands written in
  359. Lisp, the `interactive' specification says how to read the arguments.
  360. This may use the prefix argument (*note Prefix Command Arguments::.) or
  361. may read with prompting in the minibuffer (*note Minibuffers::.).  For
  362. example, the command `find-file' has an `interactive' specification
  363. which says to read a file name using the minibuffer.  The command's
  364. function body does not use the minibuffer; if you call this command
  365. from Lisp code as a function, you must supply the file name string as
  366. an ordinary Lisp function argument.
  367.  
  368.    If the command is a string or vector (i.e., a keyboard macro) then
  369. `execute-kbd-macro' is used to execute it.  You can call this function
  370. yourself (*note Keyboard Macros::.).
  371.  
  372.    If a command runs away, typing `C-g' terminates its execution
  373. immediately.  This is called "quitting" (*note Quitting::.).
  374.  
  375.  - Variable: pre-command-hook
  376.      The editor command loop runs this normal hook before each command.
  377.  
  378.  - Variable: post-command-hook
  379.      The editor command loop runs this normal hook after each command,
  380.      and also when the command loop is entered, or reentered after an
  381.      error or quit.
  382.  
  383. 
  384. File: elisp,  Node: Defining Commands,  Next: Interactive Call,  Prev: Command Overview,  Up: Command Loop
  385.  
  386. Defining Commands
  387. =================
  388.  
  389.    A Lisp function becomes a command when its body contains, at top
  390. level, a form which calls the special form `interactive'.  This form
  391. does nothing when actually executed, but its presence serves as a flag
  392. to indicate that interactive calling is permitted.  Its argument
  393. controls the reading of arguments for an interactive call.
  394.  
  395. * Menu:
  396.  
  397. * Using Interactive::     General rules for `interactive'.
  398. * Interactive Codes::     The standard letter-codes for reading arguments
  399.                              in various ways.
  400. * Interactive Examples::  Examples of how to read interactive arguments.
  401.  
  402. 
  403. File: elisp,  Node: Using Interactive,  Next: Interactive Codes,  Up: Defining Commands
  404.  
  405. Using `interactive'
  406. -------------------
  407.  
  408.    This section describes how to write the `interactive' form that
  409. makes a Lisp function an interactively-callable command.
  410.  
  411.  - Special Form: interactive ARG-DESCRIPTOR
  412.      This special form declares that the function in which it appears
  413.      is a command, and that it may therefore be called interactively
  414.      (via `M-x' or by entering a key sequence bound to it).  The
  415.      argument ARG-DESCRIPTOR declares the way the arguments to the
  416.      command are to be computed when the command is called
  417.      interactively.
  418.  
  419.      A command may be called from Lisp programs like any other
  420.      function, but then the arguments are supplied by the caller and
  421.      ARG-DESCRIPTOR has no effect.
  422.  
  423.      The `interactive' form has its effect because the command loop
  424.      (actually, its subroutine `call-interactively') scans through the
  425.      function definition looking for it, before calling the function.
  426.      Once the function is called, all its body forms including the
  427.      `interactive' form are executed, but at this time `interactive'
  428.      simply returns `nil' without even evaluating its argument.
  429.  
  430.    There are three possibilities for the argument ARG-DESCRIPTOR:
  431.  
  432.    * It may be omitted or `nil'; then the command is called with no
  433.      arguments.  This leads quickly to an error if the command requires
  434.      one or more arguments.
  435.  
  436.    * It may be a Lisp expression that is not a string; then it should
  437.      be a form that is evaluated to get a list of arguments to pass to
  438.      the command.
  439.  
  440.    * It may be a string; then its contents should consist of a code
  441.      character followed by a prompt (which some code characters use and
  442.      some ignore).  The prompt ends either with the end of the string
  443.      or with a newline.  Here is a simple example:
  444.  
  445.           (interactive "bFrobnicate buffer: ")
  446.  
  447.      The code letter `b' says to read the name of an existing buffer,
  448.      with completion.  The buffer name is the sole argument passed to
  449.      the command.  The rest of the string is a prompt.
  450.  
  451.      If there is a newline character in the string, it terminates the
  452.      prompt.  If the string does not end there, then the rest of the
  453.      string should contain another code character and prompt,
  454.      specifying another argument.  You can specify any number of
  455.      arguments in this way.
  456.  
  457.      The prompt string can use `%' to include previous argument values
  458.      in the prompt.  This is done using `format' (*note Formatting
  459.      Strings::.).  For example, here is how you could read the name of
  460.      an existing buffer followed by a new name to give to that buffer:
  461.  
  462.           (interactive "bBuffer to rename: \nsRename buffer %s to: ")
  463.  
  464.      If the first character in the string is `*', then an error is
  465.      signaled if the buffer is read-only.
  466.  
  467.      If the first character in the string is `@', and if the key
  468.      sequence used to invoke the command includes any mouse events, then
  469.      the window associated with the first of those events is selected
  470.      before the command is run.
  471.  
  472.      You can use `*' and `@' together; the order does not matter.
  473.      Actual reading of arguments is controlled by the rest of the prompt
  474.      string (starting with the first character that is not `*' or `@').
  475.  
  476. 
  477. File: elisp,  Node: Interactive Codes,  Next: Interactive Examples,  Prev: Using Interactive,  Up: Defining Commands
  478.  
  479. Code Characters for `interactive'
  480. ---------------------------------
  481.  
  482.    The code character descriptions below contain a number of key words,
  483. defined here as follows:
  484.  
  485. Completion
  486.      Provide completion.  TAB, SPC, and RET perform name completion
  487.      because the argument is read using `completing-read' (*note
  488.      Completion::.).  `?' displays a list of possible completions.
  489.  
  490. Existing
  491.      Require the name of an existing object.  An invalid name is not
  492.      accepted; the commands to exit the minibuffer do not exit if the
  493.      current input is not valid.
  494.  
  495. Default
  496.      A default value of some sort is used if the user enters no text in
  497.      the minibuffer.  The default depends on the code character.
  498.  
  499. No I/O
  500.      This code letter computes an argument without reading any input.
  501.      Therefore, it does not use a prompt string, and any prompt string
  502.      you supply is ignored.
  503.  
  504. Prompt
  505.      A prompt immediately follows the code character.  The prompt ends
  506.      either with the end of the string or with a newline.
  507.  
  508. Special
  509.      This code character is meaningful only at the beginning of the
  510.      interactive string, and it does not look for a prompt or a newline.
  511.      It is a single, isolated character.
  512.  
  513.    Here are the code character descriptions for use with `interactive':
  514.  
  515. `*'
  516.      Signal an error if the current buffer is read-only.  Special.
  517.  
  518. `@'
  519.      Select the window mentioned in the first mouse event in the key
  520.      sequence that invoked this command.  Special.
  521.  
  522. `a'
  523.      A function name (i.e., a symbol which is `fboundp').  Existing,
  524.      Completion, Prompt.
  525.  
  526. `b'
  527.      The name of an existing buffer.  By default, uses the name of the
  528.      current buffer (*note Buffers::.).  Existing, Completion, Default,
  529.      Prompt.
  530.  
  531. `B'
  532.      A buffer name.  The buffer need not exist.  By default, uses the
  533.      name of a recently used buffer other than the current buffer.
  534.      Completion, Prompt.
  535.  
  536. `c'
  537.      A character.  The cursor does not move into the echo area.  Prompt.
  538.  
  539. `C'
  540.      A command name (i.e., a symbol satisfying `commandp').  Existing,
  541.      Completion, Prompt.
  542.  
  543. `d'
  544.      The position of point as a number (*note Point::.).  No I/O.
  545.  
  546. `D'
  547.      A directory name.  The default is the current default directory of
  548.      the current buffer, `default-directory' (*note System
  549.      Environment::.).  Existing, Completion, Default, Prompt.
  550.  
  551. `e'
  552.      The first or next mouse event in the key sequence that invoked the
  553.      command.  More precisely, `e' gets events which are lists, so you
  554.      can look at the data in the lists.  *Note Input Events::.  No I/O.
  555.  
  556.      You can use `e' more than once in a single command's interactive
  557.      specification.  If the key sequence which invoked the command has
  558.      N events with parameters, the Nth `e' provides the Nth list event.
  559.      Events which are not lists, such as function keys and ASCII
  560.      characters, do not count where `e' is concerned.
  561.  
  562.      Even though `e' does not use a prompt string, you must follow it
  563.      with a newline if it is not the last code character.
  564.  
  565. `f'
  566.      A file name of an existing file (*note File Names::.).  The default
  567.      directory is `default-directory'.  Existing, Completion, Default,
  568.      Prompt.
  569.  
  570. `F'
  571.      A file name.  The file need not exist.  Completion, Default,
  572.      Prompt.
  573.  
  574. `k'
  575.      A key sequence (*note Keymap Terminology::.).  This keeps reading
  576.      events until a command (or undefined command) is found in the
  577.      current key maps.  The key sequence argument is represented as a
  578.      string or vector.  The cursor does not move into the echo area.
  579.      Prompt.
  580.  
  581.      This kind of input is used by commands such as `describe-key' and
  582.      `global-set-key'.
  583.  
  584. `m'
  585.      The position of the mark as a number.  No I/O.
  586.  
  587. `n'
  588.      A number read with the minibuffer.  If the input is not a number,
  589.      the user is asked to try again.  The prefix argument, if any, is
  590.      not used.  Prompt.
  591.  
  592. `N'
  593.      The raw prefix argument.  If the prefix argument is `nil', then a
  594.      number is read as with `n'.  Requires a number.  Prompt.
  595.  
  596. `p'
  597.      The numeric prefix argument.  (Note that this `p' is lower case.)
  598.      No I/O.
  599.  
  600. `P'
  601.      The raw prefix argument.  (Note that this `P' is upper case.)
  602.      *Note Prefix Command Arguments::.  No I/O.
  603.  
  604. `r'
  605.      Point and the mark, as two numeric arguments, smallest first.
  606.      This is the only code letter that specifies two successive
  607.      arguments rather than one.  No I/O.
  608.  
  609. `s'
  610.      Arbitrary text, read in the minibuffer and returned as a string
  611.      (*note Text from Minibuffer::.).  Terminate the input with either
  612.      LFD or RET.  (`C-q' may be used to include either of these
  613.      characters in the input.)  Prompt.
  614.  
  615. `S'
  616.      An interned symbol whose name is read in the minibuffer.  Any
  617.      whitespace character terminates the input.  (Use `C-q' to include
  618.      whitespace in the string.)  Other characters that normally
  619.      terminate a symbol (e.g., parentheses and brackets) do not do so
  620.      here.  Prompt.
  621.  
  622. `v'
  623.      A variable declared to be a user option (i.e., satisfying the
  624.      predicate `user-variable-p').  *Note High-Level Completion::.
  625.      Existing, Completion, Prompt.
  626.  
  627. `x'
  628.      A Lisp object specified in printed representation, terminated with
  629.      a LFD or RET.  The object is not evaluated.  *Note Object from
  630.      Minibuffer::.  Prompt.
  631.  
  632. `X'
  633.      A Lisp form is read as with `x', but then evaluated so that its
  634.      value becomes the argument for the command.  Prompt.
  635.  
  636. 
  637. File: elisp,  Node: Interactive Examples,  Prev: Interactive Codes,  Up: Defining Commands
  638.  
  639. Examples of Using `interactive'
  640. -------------------------------
  641.  
  642.    Here are some examples of `interactive':
  643.  
  644.      (defun foo1 ()              ; `foo1' takes no arguments,
  645.          (interactive)           ;   just moves forward two words.
  646.          (forward-word 2))
  647.           => foo1
  648.      
  649.      (defun foo2 (n)             ; `foo2' takes one argument,
  650.          (interactive "p")       ;   which is the numeric prefix.
  651.          (forward-word (* 2 n)))
  652.           => foo2
  653.      
  654.      (defun foo3 (n)             ; `foo3' takes one argument,
  655.          (interactive "nCount:") ;   which is read with the Minibuffer.
  656.          (forward-word (* 2 n)))
  657.           => foo3
  658.      
  659.      (defun three-b (b1 b2 b3)
  660.        "Select three existing buffers.
  661.      Put them into three windows, selecting the last one."
  662.          (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
  663.          (delete-other-windows)
  664.          (split-window (selected-window) 8)
  665.          (switch-to-buffer b1)
  666.          (other-window 1)
  667.          (split-window (selected-window) 8)
  668.          (switch-to-buffer b2)
  669.          (other-window 1)
  670.          (switch-to-buffer b3))
  671.           => three-b
  672.      (three-b "*scratch*" "declarations.texi" "*mail*")
  673.           => nil
  674.  
  675. 
  676. File: elisp,  Node: Interactive Call,  Next: Command Loop Info,  Prev: Defining Commands,  Up: Command Loop
  677.  
  678. Interactive Call
  679. ================
  680.  
  681.    After the command loop has translated a key sequence into a
  682. definition, it invokes that definition using the function
  683. `command-execute'.  If the definition is a function that is a command,
  684. `command-execute' calls `call-interactively', which reads the arguments
  685. and calls the command.  You can also call these functions yourself.
  686.  
  687.  - Function: commandp OBJECT
  688.      Returns `t' if OBJECT is suitable for calling interactively; that
  689.      is, if OBJECT is a command.  Otherwise, returns `nil'.
  690.  
  691.      The interactively callable objects include strings and vectors
  692.      (treated as keyboard macros), lambda expressions that contain a
  693.      top-level call to `interactive', byte-code function objects,
  694.      autoload objects that are declared as interactive (non-`nil'
  695.      fourth argument to `autoload'), and some of the primitive
  696.      functions.
  697.  
  698.      A symbol is `commandp' if its function definition is `commandp'.
  699.  
  700.      Keys and keymaps are not commands.  Rather, they are used to look
  701.      up commands (*note Keymaps::.).
  702.  
  703.      See `documentation' in *Note Accessing Documentation::, for a
  704.      realistic example of using `commandp'.
  705.  
  706.  - Function: call-interactively COMMAND &optional RECORD-FLAG
  707.      This function calls the interactively callable function COMMAND,
  708.      reading arguments according to its interactive calling
  709.      specifications.  An error is signaled if COMMAND cannot be called
  710.      interactively (i.e., it is not a command).  Note that keyboard
  711.      macros (strings and vectors) are not accepted, even though they
  712.      are considered commands.
  713.  
  714.      If RECORD-FLAG is non-`nil', then this command and its arguments
  715.      are unconditionally added to the list `command-history'.
  716.      Otherwise, the command is added only if it uses the minibuffer to
  717.      read an argument.  *Note Command History::.
  718.  
  719.  - Function: command-execute COMMAND &optional RECORD-FLAG
  720.      This function executes COMMAND as an editing command.  The
  721.      argument COMMAND must satisfy the `commandp' predicate; i.e., it
  722.      must be an interactively callable function or a string.
  723.  
  724.      A string or vector as COMMAND is executed with
  725.      `execute-kbd-macro'.  A function is passed to
  726.      `call-interactively', along with the optional RECORD-FLAG.
  727.  
  728.      A symbol is handled by using its function definition in its place.
  729.      A symbol with an `autoload' definition counts as a command if it
  730.      was declared to stand for an interactively callable function.
  731.      Such a definition is handled by loading the specified library and
  732.      then rechecking the definition of the symbol.
  733.  
  734.  - Command: execute-extended-command PREFIX-ARGUMENT
  735.      This function reads a command name from the minibuffer using
  736.      `completing-read' (*note Completion::.).  Then it uses
  737.      `command-execute' to call the specified command.  Whatever that
  738.      command returns becomes the value of `execute-extended-command'.
  739.  
  740.      If the command asks for a prefix argument, the value
  741.      PREFIX-ARGUMENT is supplied.  If `execute-extended-command' is
  742.      called interactively, the current raw prefix argument is used for
  743.      PREFIX-ARGUMENT, and thus passed on to whatever command is run.
  744.  
  745.      `execute-extended-command' is the normal definition of `M-x', so
  746.      it uses the string `M-x ' as a prompt.  (It would be better to
  747.      take the prompt from the events used to invoke
  748.      `execute-extended-command', but that is painful to implement.)  A
  749.      description of the value of the prefix argument, if any, also
  750.      becomes part of the prompt.
  751.  
  752.           (execute-extended-command 1)
  753.           ---------- Buffer: Minibuffer ----------
  754.           M-x forward-word RET
  755.           ---------- Buffer: Minibuffer ----------
  756.                => t
  757.  
  758.  - Function: interactive-p
  759.      This function returns `t' if the containing function (the one that
  760.      called `interactive-p') was called interactively, with the function
  761.      `call-interactively'.  (It makes no difference whether
  762.      `call-interactively' was called from Lisp or directly from the
  763.      editor command loop.)  Note that if the containing function was
  764.      called by Lisp evaluation (or with `apply' or `funcall'), then it
  765.      was not called interactively.
  766.  
  767.      The usual application of `interactive-p' is for deciding whether to
  768.      print an informative message.  As a special exception,
  769.      `interactive-p' returns `nil' whenever a keyboard macro is being
  770.      run.  This is to suppress the informative messages and speed
  771.      execution of the macro.
  772.  
  773.      For example:
  774.  
  775.           (defun foo ()
  776.             (interactive)
  777.             (and (interactive-p)
  778.                  (message "foo")))
  779.                => foo
  780.           
  781.           (defun bar ()
  782.             (interactive)
  783.             (setq foobar (list (foo) (interactive-p))))
  784.                => bar
  785.           
  786.           ;; Type `M-x foo'.
  787.                -| foo
  788.           
  789.           ;; Type `M-x bar'.
  790.           ;; This does not print anything.
  791.           
  792.           foobar
  793.                => (nil t)
  794.  
  795. 
  796. File: elisp,  Node: Command Loop Info,  Next: Input Events,  Prev: Interactive Call,  Up: Command Loop
  797.  
  798. Information from the Command Loop
  799. =================================
  800.  
  801.    The editor command loop sets several Lisp variables to keep status
  802. records for itself and for commands that are run.
  803.  
  804.  - Variable: last-command
  805.      This variable records the name of the previous command executed by
  806.      the command loop (the one before the current command).  Normally
  807.      the value is a symbol with a function definition, but this is not
  808.      guaranteed.
  809.  
  810.      The value is set by copying the value of `this-command' when a
  811.      command returns to the command loop, except when the command
  812.      specifies a prefix argument for the following command.
  813.  
  814.  - Variable: this-command
  815.      This variable records the name of the command now being executed by
  816.      the editor command loop.  Like `last-command', it is normally a
  817.      symbol with a function definition.
  818.  
  819.      This variable is set by the command loop just before the command
  820.      is run, and its value is copied into `last-command' when the
  821.      command finishes (unless the command specifies a prefix argument
  822.      for the following command).
  823.  
  824.      Some commands change the value of this variable during their
  825.      execution, simply as a flag for whatever command runs next.  In
  826.      particular, the functions that kill text set `this-command' to
  827.      `kill-region' so that any kill commands immediately following will
  828.      know to append the killed text to the previous kill.
  829.  
  830.  - Function: this-command-keys
  831.      This function returns a string or vector containing the key
  832.      sequence that invoked the present command, plus any previous
  833.      commands that generated the prefix argument for this command.  The
  834.      value is a string if all those events were characters.  *Note
  835.      Input Events::.
  836.  
  837.           (this-command-keys)
  838.           ;; Now type `C-u C-x C-e'.
  839.                => "^U^X^E"
  840.  
  841.  - Variable: last-nonmenu-event
  842.      This variable holds the last input event read as part of a key
  843.      sequence, aside from events resulting from mouse menus.
  844.  
  845.      One use of this variable is to figure out a good default location
  846.      to pop up another menu.
  847.  
  848.  - Variable: last-command-event
  849.  - Variable: last-command-char
  850.      This variable is set to the last input event that was read by the
  851.      command loop as part of a command.  The principal use of this
  852.      variable is in `self-insert-command', which uses it to decide which
  853.      character to insert.
  854.  
  855.           last-command-char
  856.           ;; Now type `C-u C-x C-e'.
  857.                => 5
  858.  
  859.      The value is 5 because that is the ASCII code for `C-e'.
  860.  
  861.      The alias `last-command-char' exists for compatibility with Emacs
  862.      version 18.
  863.  
  864.  - Variable: last-event-frame
  865.      This variable records which frame the last input event was
  866.      directed to.  Usually this is the frame that was selected when the
  867.      event was generated, but if that frame has redirected input focus
  868.      to another frame, the value is the frame to which the event was
  869.      redirected.  *Note Input Focus::.
  870.  
  871.  - Variable: echo-keystrokes
  872.      This variable determines how much time should elapse before command
  873.      characters echo.  Its value must be an integer, which specifies the
  874.      number of seconds to wait before echoing.  If the user types a
  875.      prefix key (say `C-x') and then delays this many seconds before
  876.      continuing, the key `C-x' is echoed in the echo area.  Any
  877.      subsequent characters in the same command will be echoed as well.
  878.  
  879.      If the value is zero, then command input is not echoed.
  880.  
  881. 
  882. File: elisp,  Node: Input Events,  Next: Reading Input,  Prev: Command Loop Info,  Up: Command Loop
  883.  
  884. Input Events
  885. ============
  886.  
  887.    The Emacs command loop reads a sequence of "input events" that
  888. represent keyboard or mouse activity.  The events for keyboard activity
  889. are characters or symbols; mouse events are always lists.  This section
  890. describes the representation and meaning of input events in detail.
  891.  
  892.    A command invoked using events that are lists can get the full
  893. values of these events using the `e' interactive code.  *Note
  894. Interactive Codes::.
  895.  
  896.    A key sequence that starts with a mouse event is read using the
  897. keymaps of the buffer in the window that the mouse was in, not the
  898. current buffer.  This does not imply that clicking in a window selects
  899. that window or its buffer--that is entirely under the control of the
  900. command binding of the key sequence.
  901.  
  902.  - Function: eventp OBJECT
  903.      This function returns non-`nil' if EVENT is an input event.
  904.  
  905. * Menu:
  906.  
  907. * Keyboard Events::        Ordinary characters-keys with symbols on them.
  908. * Function Keys::        Function keys-keys with names, not symbols.
  909. * Click Events::        Pushing and releasing a mouse button.
  910. * Drag Events::            Moving the mouse before releasing the button.
  911. * Button-Down Events::        A button was pushed and not yet released.
  912. * Repeat Events::               Double and triple click (or drag, or down).
  913. * Motion Events::        Just moving the mouse, not pushing a button.
  914. * Focus Events::        Moving the mouse between frames.
  915. * Event Examples::        Examples of the lists for mouse events.
  916. * Classifying Events::        Finding the modifier keys in an event symbol.
  917.                 Event types.
  918. * Accessing Events::        Functions to extract info from events.
  919. * Strings of Events::           Special considerations for putting
  920.                   keyboard character events in a string.
  921.  
  922. 
  923. File: elisp,  Node: Keyboard Events,  Next: Function Keys,  Up: Input Events
  924.  
  925. Keyboard Events
  926. ---------------
  927.  
  928.    There are two kinds of input you can get from the keyboard: ordinary
  929. keys, and function keys.  Ordinary keys correspond to characters; the
  930. events they generate are represented in Lisp as characters.  In Emacs
  931. versions 18 and earlier, characters were the only events.
  932.  
  933.    An input character event consists of a "basic code" between 0 and
  934. 255, plus any or all of these "modifier bits":
  935.  
  936. meta
  937.      The 2**23 bit in the character code indicates a character typed
  938.      with the meta key held down.
  939.  
  940. control
  941.      The 2**22 bit in the character code indicates a non-ASCII control
  942.      character.
  943.  
  944.      ASCII control characters such as `C-a' have special basic codes of
  945.      their own, so Emacs needs no special bit to indicate them.  Thus,
  946.      the code for `C-a' is just 1.
  947.  
  948.      But if you type a control combination not in ASCII, such as `%'
  949.      with the control key, the numeric value you get is the code for
  950.      `%' plus 2**22 (assuming the terminal supports non-ASCII control
  951.      characters).
  952.  
  953. shift
  954.      The 2**21 bit in the character code indicates an ASCII control
  955.      character typed with the shift key held down.
  956.  
  957.      For letters, the basic code indicates upper versus lower case; for
  958.      digits and punctuation, the shift key selects an entirely different
  959.      character with a different basic code.  In order to keep within
  960.      the ASCII character set whenever possible, Emacs avoids using the
  961.      2**21 bit for those characters.
  962.  
  963.      However, ASCII provides no way to distinguish `C-A' from `C-A', so
  964.      Emacs uses the 2**21 bit in `C-A' and not in `C-a'.
  965.  
  966. hyper
  967.      The 2**20 bit in the character code indicates a character typed
  968.      with the hyper key held down.
  969.  
  970. super
  971.      The 2**19 bit in the character code indicates a character typed
  972.      with the super key held down.
  973.  
  974. alt
  975.      The 2**18 bit in the character code indicates a character typed
  976.      with the alt key held down.  (On some terminals, the key labeled
  977.      ALT is actually the meta key.)
  978.  
  979.    In the future, Emacs may support a larger range of basic codes.  We
  980. may also move the modifier bits to larger bit numbers.  Therefore, you
  981. should avoid mentioning specific bit numbers in your program.  Instead,
  982. the way to test the modifier bits of a character is with the function
  983. `event-modifiers' (*note Classifying Events::.).
  984.  
  985. 
  986. File: elisp,  Node: Function Keys,  Next: Click Events,  Prev: Keyboard Events,  Up: Input Events
  987.  
  988. Function Keys
  989. -------------
  990.  
  991.    Most keyboards also have "function keys"--keys which have names or
  992. symbols that are not characters.  Function keys are represented in Lisp
  993. as symbols; the symbol's name is the function key's label.  For example,
  994. pressing a key labeled F1 places the symbol `f1' in the input stream.
  995.  
  996.    For all keyboard events, the event type (which classifies the event
  997. for key lookup purposes) is identical to the event--it is the character
  998. or the symbol.  *Note Classifying Events::.
  999.  
  1000.    Here are a few special cases in the symbol naming convention for
  1001. function keys:
  1002.  
  1003. `backspace', `tab', `newline', `return', `delete'
  1004.      These keys correspond to common ASCII control characters that have
  1005.      special keys on most keyboards.
  1006.  
  1007.      In ASCII, `C-i' and TAB are the same character.  Emacs lets you
  1008.      distinguish them if you wish, by returning the former as the
  1009.      integer 9, and the latter as the symbol `tab'.
  1010.  
  1011.      Most of the time, it's not useful to distinguish the two.  So
  1012.      normally `function-key-map' is set up to map `tab' into 9.  Thus, a
  1013.      key binding for character code 9 also applies to `tab'.  Likewise
  1014.      for the other symbols in this group.  The function `read-char'
  1015.      also converts these events into characters.
  1016.  
  1017.      In ASCII, BS is really `C-h'.  But `backspace' converts into the
  1018.      character code 127 (DEL), not into code 8 (BS).  This is what most
  1019.      users prefer.
  1020.  
  1021. `kp-add', `kp-decimal', `kp-divide', ...
  1022.      Keypad keys (to the right of the regular keyboard).
  1023.  
  1024. `kp-0', `kp-1', ...
  1025.      Keypad keys with digits.
  1026.  
  1027. `kp-f1', `kp-f2', `kp-f3', `kp-f4'
  1028.      Keypad PF keys.
  1029.  
  1030. `left', `up', `right', `down'
  1031.      Cursor arrow keys
  1032.  
  1033.    You can use the modifier keys CTRL, META, HYPER, SUPER, ALT and
  1034. SHIFT with function keys.  The way to represent them is with prefixes
  1035. in the symbol name:
  1036.  
  1037. `A-'
  1038.      The alt modifier.
  1039.  
  1040. `C-'
  1041.      The control modifier.
  1042.  
  1043. `H-'
  1044.      The hyper modifier.
  1045.  
  1046. `M-'
  1047.      The meta modifier.
  1048.  
  1049. `S-'
  1050.      The shift modifier.
  1051.  
  1052. `s-'
  1053.      The super modifier.
  1054.  
  1055.    Thus, the symbol for the key F3 with META held down is `M-F3'.  When
  1056. you use more than one prefix, we recommend you write them in
  1057. alphabetical order (though the order does not matter in arguments to
  1058. the key-binding lookup and modification functions).
  1059.  
  1060. 
  1061. File: elisp,  Node: Click Events,  Next: Drag Events,  Prev: Function Keys,  Up: Input Events
  1062.  
  1063. Click Events
  1064. ------------
  1065.  
  1066.    When the user presses a mouse button and releases it at the same
  1067. location, that generates a "click" event.  Mouse click events have this
  1068. form:
  1069.  
  1070.      (EVENT-TYPE
  1071.       (WINDOW BUFFER-POS
  1072.        (COLUMN . ROW) TIMESTAMP)
  1073.       CLICK-COUNT)
  1074.  
  1075.    Here is what the elements normally mean:
  1076.  
  1077. EVENT-TYPE
  1078.      This is a symbol that indicates which mouse button was used.  It is
  1079.      one of the symbols `mouse-1', `mouse-2', ..., where the buttons
  1080.      are numbered numbered left to right.
  1081.  
  1082.      You can also use prefixes `A-', `C-', `H-', `M-', `S-' and `s-'
  1083.      for modifiers alt, control, hyper, meta, shift and super, just as
  1084.      you would with function keys.
  1085.  
  1086.      This symbol also serves as the event type of the event.  Key
  1087.      bindings describe events by their types; thus, if there is a key
  1088.      binding for `mouse-1', that binding would apply to all events whose
  1089.      EVENT-TYPE is `mouse-1'.
  1090.  
  1091. WINDOW
  1092.      This is the window in which the click occurred.
  1093.  
  1094. COLUMN
  1095. ROW
  1096.      These are the column and row of the click, relative to the top left
  1097.      corner of WINDOW, which is `(0 . 0)'.
  1098.  
  1099. BUFFER-POS
  1100.      This is the buffer position of the character clicked on.
  1101.  
  1102. TIMESTAMP
  1103.      This is the time at which the event occurred, in milliseconds.
  1104.      (Since this value wraps around the entire range of Emacs Lisp
  1105.      integers in about five hours, it is useful only for relating the
  1106.      times of nearby events.)
  1107.  
  1108. CLICK-COUNT
  1109.      This is the number of rapid repeated presses so far of the same
  1110.      mouse button.  *Note Repeat Events::.
  1111.  
  1112.    The meanings of BUFFER-POS, ROW and COLUMN are somewhat different
  1113. when the event location is in a special part of the screen, such as the
  1114. mode line or a scroll bar.
  1115.  
  1116.    If the location is in a scroll bar, then BUFFER-POS is the symbol
  1117. `vertical-scroll-bar' or `horizontal-scroll-bar', and the pair `(COLUMN
  1118. . ROW)' is replaced with a pair `(PORTION . WHOLE)', where PORTION is
  1119. the distance of the click from the top or left end of the scroll bar,
  1120. and WHOLE is the length of the entire scroll bar.
  1121.  
  1122.    If the position is on a mode line or the vertical line separating
  1123. WINDOW from its neighbor to the right, then BUFFER-POS is the symbol
  1124. `mode-line' or `vertical-line'.  For the mode line, ROW does not have
  1125. meaningful data.  For the vertical line, COLUMN does not have
  1126. meaningful data.
  1127.  
  1128.    BUFFER-POS may be a list containing a symbol (one of the symbols
  1129. listed above) instead of just the symbol.  This is what happens after
  1130. the imaginary prefix keys for these events are inserted into the input
  1131. stream.  *Note Key Sequence Input::.
  1132.  
  1133. 
  1134. File: elisp,  Node: Drag Events,  Next: Button-Down Events,  Prev: Click Events,  Up: Input Events
  1135.  
  1136. Drag Events
  1137. -----------
  1138.  
  1139.    With Emacs, you can have a drag event without even changing your
  1140. clothes.  A "drag event" happens every time the user presses a mouse
  1141. button and then moves the mouse to a different character position before
  1142. releasing the button.  Like all mouse events, drag events are
  1143. represented in Lisp as lists.  The lists record both the starting mouse
  1144. position and the final position, like this:
  1145.  
  1146.      (EVENT-TYPE
  1147.       (WINDOW1 BUFFER-POS1
  1148.        (COLUMN1 . ROW1) TIMESTAMP1)
  1149.       (WINDOW2 BUFFER-POS2
  1150.        (COLUMN2 . ROW2) TIMESTAMP2)
  1151.       CLICK-COUNT)
  1152.  
  1153.    For a drag event, the name of the symbol EVENT-TYPE contains the
  1154. prefix `drag-'.  The second and third elements of the event give the
  1155. starting and ending position of the drag.  Aside from that, the data
  1156. have the same meanings as in a click event (*note Click Events::.).  You
  1157. can access the second element of any mouse event in the same way, with
  1158. no need to distinguish drag events from others.
  1159.  
  1160.    The `drag-' prefix follows the modifier key prefixes such as `C-'
  1161. and `M-'.
  1162.  
  1163.    If `read-key-sequence' receives a drag event which has no key
  1164. binding, and the corresponding click event does have a binding, it
  1165. changes the drag event into a click event at the drag's starting
  1166. position.  This means that you don't have to distinguish between click
  1167. and drag events unless you want to.
  1168.  
  1169. 
  1170. File: elisp,  Node: Button-Down Events,  Next: Repeat Events,  Prev: Drag Events,  Up: Input Events
  1171.  
  1172. Button-Down Events
  1173. ------------------
  1174.  
  1175.    Click and drag events happen when the user releases a mouse button.
  1176. They cannot happen earlier, because there is no way to distinguish a
  1177. click from a drag until the button is released.
  1178.  
  1179.    If you want to take action as soon as a button is pressed, you need
  1180. to handle "button-down" events.(1).  These occur as soon as a button is
  1181. pressed.  They are represented by lists which look exactly like click
  1182. events (*note Click Events::.), except that the name of EVENT-TYPE
  1183. contains the prefix `down-'.  The `down-' prefix follows the modifier
  1184. key prefixes such as `C-' and `M-'.
  1185.  
  1186.    The function `read-key-sequence', and the Emacs command loop, ignore
  1187. any button-down events that don't have command bindings.  This means
  1188. that you need not worry about defining button-down events unless you
  1189. want them to do something.  The usual reason to define a button-down
  1190. event is so that you can track mouse motion (by reading motion events)
  1191. until the button is released.  *Note Motion Events::.
  1192.  
  1193.    ---------- Footnotes ----------
  1194.  
  1195.    (1)  Button-down is the conservative antithesis of drag.
  1196.  
  1197.